package zhongbo.java.air.monitor.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.exception.MyException;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.monitor.model.AirAlertLog;
import zhongbo.java.air.monitor.service.IJtsService;

@RestController
@RequestMapping("/alertLog")
@Api(tags = "告警日志记录")
public class AirAlertLogController {
    @Autowired
    private IJtsService jtsService;

    @PostMapping("/add")
    @ApiOperation("添加警告日志")
    public ResultVo<AirAlertLog> addAirAlertLog(@RequestBody AirAlertLog airAlertLog) {
        try {
          AirAlertLog airAlertLog1 = jtsService.addAirAlertLog(airAlertLog);
            return ResultVo.ok(airAlertLog1);
        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }

    }

    @GetMapping("/delete")
    @ApiOperation("/删除警告日志")
    public ResultVo<String> deleteAirAlertLog(@RequestParam String Icao) {
        try {
            jtsService.deleteAirAlertLog(Icao);
            return ResultVo.ok("1");
        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }
    }

    @PostMapping("/edit")
    @ApiOperation("更新警告日志")
    public ResultVo<AirAlertLog> updateAirAlertLog(@RequestBody AirAlertLog airAlertLog) {
        try {
          AirAlertLog airAlertLog1 = jtsService.updateAirAlertLog(airAlertLog);
            return ResultVo.ok(airAlertLog1);

        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }
    }

    @GetMapping("/findOne")
    @ApiOperation("获取警告日志")
    public ResultVo<AirAlertLog> getAirAlertLog(@RequestParam String Id) {
        try {
            AirAlertLog airAlertLog = jtsService.selectAirAlertLog(Id);
            return ResultVo.ok(airAlertLog);
        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }
    }

    @GetMapping("findPage")
    @ApiOperation("分页查询2")
    public ResultVo<PageVo<AirAlertLog>> pageByIcaoCode(
            @RequestParam(defaultValue = "1") Integer pageNumber,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String icaoCode,
            @RequestParam(required = false)
            String startTime,
            @RequestParam(required = false)
            String endTime,
            @RequestParam
            String oderByField,
            @RequestParam
            boolean orderByAsc,
            @RequestParam
            String searchField,
            @RequestParam
            String keyword
    ) {

        try {
            PageVo<AirAlertLog> page = jtsService.pageByIcaoCode(pageNumber, pageSize, icaoCode, startTime, endTime, oderByField, orderByAsc,searchField,  keyword);
            return ResultVo.ok(page);
        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }
    }

}
